<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
	<script src="../../../res/layuis/dist/layui.js"></script>
	<script src="../../res/js/jquery-3.4.1.min.js"></script>
	<link rel="stylesheet" href="../../../res/layuis/dist/css/layui.css" media="all">
<style>
form {
	margin: 20px;
}



#treeclass{
line-height: 38px;
}
.downpanel dl dd:hover {
	background-color: inherit;
}

#classtree {
	position:absolute;
	top:35px;
	
	z-index: 99;
	opacity: 0.9;
	background-color: #FCFCFC ;
	width:450px;
	font-weight: bold;
}

</style>
</head>
<body>
	<form class="layui-form" action="" lay-filter="example">
	<input type="hidden" name="modId" id="modId">
		<div class="layui-form-item">
			<label class="layui-form-label">模块名称</label>
			<div class="layui-input-block">
				<input type="text" id="modName" name="modName" lay-verify="modName"
					autocomplete="off" placeholder="" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">模块url</label>
			<div class="layui-input-block">
				<input type="text" name="modLocaton" id="modLocaton" lay-verify="modLocaton"
					autocomplete="off" placeholder="一级模块可用不用填写" class="layui-input">
			</div>
		</div>

			<label class="layui-form-label">上级模块</label>
			<div
				class="layui-unselect layui-input-block layui-form-select downpanel">
				<div class="layui-select-title" id="xiala">
					<span class="layui-input layui-unselect" id="treeclass"  >不选则为根模块</span>
					<input type="hidden" id="xia" name="modSuperiors" > 
					<i class=" layui-edge" id="i"></i>
				</div>
				<div hidden class=" demo-tree" id="classtree"></div>
			</div>
		</div>




		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">模块描述</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" class="layui-textarea" id="modRemark" name="modRemark" lay-verify="modRemark"></textarea>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">

				<button type="submit" class="layui-btn" lay-submit=""
					lay-filter="demo1">立即提交</button>
			</div>
		</div>
	</form>
	<script>
		layui.use([ 'tree', 'form' ], function() {
		var tree = layui.tree, form = layui.form;
			
			form.verify({
				 modName: function(value){
				      if(value==""){
				        return '不能为空';
				      };
				      if(value.length > 100){
				    	  return '最多10个字符啊';
				      }
				    }
			 	, modLocaton: function(value){
					      if(value.length > 100){
						    	  return '最多10个字符啊';
						      }
						    }
				 ,modRemark: function(value){
				      if(value.length > 50){
				    	  return '最多50个字符啊';
				      }
				    } 
					    
			 	 });
			
			if(getQueryStringOne("id")!=null){
				$("#modId").val(getQueryStringOne("id"));
				var url = "../../../ModuleAction/findbyid";
				var data = {modId:getQueryStringOne("id")};
				$.post(url,data,function(obj){
					$("#modName").val(obj.modName);
					$("#modLocaton").val(obj.modLocaton)
					if(obj.fumodName!=null){
						$("#xia").val(obj.modSuperiors)
					$("#treeclass").html(obj.fumodName)
					}
					
					$("#modRemark").val(obj.modRemark)
				})
			}
			var zhangtai = false;
			
			
			var url = "../../../ModuleAction/findAlla";
			var data={id:getQueryStringOne("id")};
				
			
			$.post(url,data,function(obj){
				tree.render({
					elem : "#classtree",
					data : obj
					,onlyIconControl: true  //是否仅允许节点左侧图标控制展开收缩
				    ,click: function(obj){
				    	$("#classtree").hide();
				      $("#xia").val(obj.data.id);
				      $("#treeclass").html(obj.data.title);
				     
				    }
				});
			});
			
			
			
			 form.on('submit(demo1)', function(data){
				    /* layer.alert(JSON.stringify(data.field), {
				      title: '最终的提交信息'
				    }) */
				    var url="../../../ModuleAction/addOrupdate"
				    var index = parent.layer.getFrameIndex(window.name);
				    $.post(url,data.field,function(obj){
				    	if(obj.state==1){
				    		layer.msg("操作成功",{icon:1,time:1000},function(){
				    			parent.layer.close(index);//关闭当前页  
			        			 // window.location.reload();
			        		})
				    	
		   				//window.parent.location.replace(location.href)//刷新父级页面  
				    	}
				    })
				    return false;
				  });
			
			$("#xiala").on("click", function() {
				if (zhangtai) {
					$("#classtree").hide();
					$("#xiala").append('<i class=" layui-edge" id="i"></i>'); 
				}else {
					$("#classtree").show();
					$("#i").remove();
				}
				zhangtai = !zhangtai;
			})
		})
		function getQueryStringOne(key) {
			var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return decodeURI(r[2]);
			return null;
		}
	</script>
</body>
</html><SCRIPT ></SCRIPT>